#include "sirCaractere.h"

sirCaractere::sirCaractere()
{
    s=new char;
}
sirCaractere::sirCaractere(int x)
{
    s=new char[100];
}
sirCaractere::~sirCaractere()
{}

istream& operator>>(istream& in, sirCaractere x)
{
    in>>x.s;
    return in;
}

ostream& operator<<(ostream& out, sirCaractere x)
{
    out<<x.s;
    return out;
}

int sirCaractere::size()
{
    int i=0;
    while (s[i]!='\0')
        i++;
    return i;
}
bool sirCaractere::operator<(sirCaractere x)
{
    int i=0;
    while ((i<this->size())&&(i<x.size()))
    {
        if (this->s[i]>x.s[i])
            return false;
        i++;
    }
    if (this->size()<x.size())
        return true;
    else return false;
}

bool sirCaractere::operator>(sirCaractere x)
{
    int i=0;
    while ((i<this->size())&&(i<x.size()))
    {
        if (this->s[i]<x.s[i])
            return false;
        i++;
    }
    if (this->size()>x.size())
        return true;
    else return false;
}

bool sirCaractere::operator==(sirCaractere x)
{
    int i=0;
    if (this->size()!=x.size())
        return false;
    else {
        while ((i<this->size()) && (i<x.size()))
        {
            if (this->s[i]!=x.s[i])
                return false;
            i++;
            
        }
        
        return true;
    }
}

//supraincarcarea operatorilor de concatenare

sirCaractere sirCaractere::operator+(sirCaractere s2)
{
    sirCaractere rez;
    int i=0;
    for (int j=0;j<this->size();j++,i++)
        rez.s[i]=this->s[i];
    for (int k=0;k<s2.size();k++,i++)
        rez.s[i]=s2.s[k];
    return rez;
}

sirCaractere operator+(char a,sirCaractere b)
{
    sirCaractere rez;
    int i=0;
    rez.s[i]=a;
    i++;
    for (int j=0;j<b.size();j++,i++)
    {
        rez.s[i]=b.s[j];
    }
    return rez;
}

sirCaractere operator+(sirCaractere b, char a)
{
    sirCaractere rez;
    int i=0;
    for (int j=0;j<b.size();j++,i++)
    {
        rez.s[i]=b.s[j];
    }
    rez.s[i]=a;
    return rez;
}

